package products

import (
	"github.com/jinzhu/gorm"
	"time"
)

//CREATE TABLE `product_pakages` (
//  `id` int NOT NULL AUTO_INCREMENT,
//  `name` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
//  `product_id` int DEFAULT NULL,
//  `duration` int DEFAULT NULL,
//  `duration_unit` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
//  `price` decimal(10,2) DEFAULT NULL,
//  `created_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
//  `updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
//  PRIMARY KEY (`id`)
//) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

type ProductPackages struct {
	Id           int       `json:"id" gorm:"primary_key;column:id"`
	Name         string    `json:"name" gorm:"column:name"`
	ProductId    int       `json:"product_id" gorm:"column:product_id"`
	Duration     int       `json:"duration" gorm:"column:duration"`
	DurationUnit string    `json:"duration_unit" gorm:"column:duration_unit"`
	Price        float64   `json:"price" gorm:"column:price"`
	CreatedAt    time.Time `json:"created_at" gorm:"column:created_at"`
	UpdatedAt    time.Time `json:"updated_at" gorm:"column:updated_at"`
}

func (p *ProductPackages) TableName() string {
	return "product_packages"
}

func (p *ProductPackages) Create(db *gorm.DB) error {
	return db.Create(p).Error
}
func (p *ProductPackages) Update(db *gorm.DB) error {
	return db.Update(p).Error
}
func (p *ProductPackages) GetById(db *gorm.DB) error {
	return db.Where("id = ?", p.Id).First(p).Error
}
